// pages/policy/policy.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    c_id: 2,
    flag:0
  },

  onPullDownRefresh: function () {

  },

  switchList: function (e) {
    wx.showLoading({
      title: '加载中...',
    })
    this.setData({
      c_id: e.currentTarget.dataset.current
    })
    setTimeout(() => {
      wx.hideLoading()
    }, 500)
    console.log(this.data.c_id)
    this.loadGird()
  },

  onLoad() {
    this.loadGird()
    this.loadCom()
  },

  loadGird() {
    wx.showLoading({
      title: '加载中...',
    })
    let access_token = wx.getStorageSync('access_token')
    wx.request({
      url: 'https://baokang.wshoto.com/wx/gridlist',
      data: {
        access_token: access_token,
      },
      success: (res) => {
        console.log(res)
        if(res.data.code >= 500){
          app.getLogin().then(function(){
            console.log('二次登录。。。')
          })
        }
        else if (res.data.code == 1) {
          this.setData({
            girdList: res.data.list,
            flag:1
          })
        }
      },
      complete:(res)=>{
        wx.hideLoading()
      }
    })
  },

  loadCom(){
    let access_token = wx.getStorageSync('access_token')
    wx.request({
      url: 'https://baokang.wshoto.com/wx/comlist',
      data: {
        access_token: access_token,
      },
      success: (res) => {
        console.log(res)
        if (res.data.code == 1) {
          this.setData({
            comList: res.data.list
          })
        }
      }
    })
  },
})